<?php 
echo $this->Html->css('jquery.multiselect');
echo $this->Html->script('jquery.multiselect');
?>
<script type="text/javascript">
<!--


$(function() {
	$("#kenh_id").multiselect({
		   selectedText: "đã chọn # trong # Kênh",
		   checkAllText: 'Chọn Tất cả',
			uncheckAllText: 'Bỏ chọn tất cả',
		   noneSelectedText: '-- Chọn Nhân Viên --'
		});
	$(".soluong").keydown(function(e) {
		arr_key = new Array();
		arr_key[8]=8;
		arr_key[9]=9;
		arr_key[35]=35;
		arr_key[36]=36;
		arr_key[37]=37;
		arr_key[39]=39;
		arr_key[46]=46;
        if ( arr_key[e.keyCode]!==undefined) {}
        else {
            if (e.keyCode < 48 || e.keyCode > 57 ) {
                e.preventDefault(); 
            }   
        }
    });
	$( ".thoigian" ).datepicker({
								showOtherMonths: true,
								selectOtherMonths: true,
								changeMonth: true,								
								dateFormat: "dd-mm-yy",
								showOn: "both",
								buttonImage:$('#root').val()+"img/calendar.jpg",
								buttonImageOnly: true
	 							});


});
function validate()
{
	if($(".thoigian").val()=='')
	{
		alert('Bạn chưa chọn ngày');
		return false;
	}
	if($("#kenh_id").val()==null)
	{
		alert('Bạn chưa chọn nhân sự');
		return false;
	}
	
	if($(".cap4").val()=='')
	{
		alert('Bạn chưa chọn địa điểm');
		return false;
	}
	return true;
}
//-->
</script>
<?php
$numhh = count($hanghoas); 
echo $form->create('Chitieungay',array('onsubmit'=>'return validate()','url'=>array('action'=>'suachitieu',$id)));
echo $form->input('root',array('id'=>'root','type'=>'hidden','value'=>$this->webroot));
//echo $form->input('thu',array('label'=>false,'id'=>'thu','type'=>'text'));
?>
<table id ='tables'>
<tr>
<th rowspan=2>STT</th>
<th rowspan=2>Đội</th>
<th rowspan=2>Địa Điểm</th>
<th rowspan=2>Ngày</th>
<th rowspan=2>Thành viên tham gia</th>
<th colspan=<?php echo $numhh?>>Chỉ tiêu</th>
<th rowspan=2>Ghi chú</th>
</tr>
<tr>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<th><?php echo $valhh ?></th>
<?php endforeach;?>
</tr>

<tr id='them'>
<td></td>
<?php echo $form->input('idkh',array('type'=>'hidden','value'=>$chitieungays['Kehoachbhld']['id']))?>
<?php echo $form->input('nhanvien_id',array('type'=>'hidden','value'=>$chitieungays['Kehoachbhld']['nhanvien_id']))?>
<td><?php echo $form->input('doi',array('label'=>false,'id'=>'doi','type'=>'text' ,'value'=>$chitieungays['Kehoachbhld']['tendoi']))?></td>
<td><?php //echo $form->input('diadiem',array('label'=>false,'class'=>'diadiem','type'=>'text','value'=>''))?></td>
<td><?php echo $form->input('thoigian',array('label'=>false,'class'=>'thoigian','type'=>'text','value'=>date('d-m-Y',strtotime($chitieungays['Kehoachbhld']['thoigian']))))?></td>
<td><div id='kenh'><?php echo $form->input('thanhvien',array('id'=>'kenh_id','label'=>'Kênh','multiple'=>"multiple",'options'=>$kenhs,'selected'=>$nhansu,'style'=>'width:100px'))?></div></td>
<?php foreach ($hanghoas as $keyhh =>$valhh):
		foreach ($chitieungays['Chitieungay'] as $ctngay)
		{
			if($ctngay['hanghoa_id']==$keyhh)
			{
				echo '<td><input class="soluong" name=data[Chitieungay][hanghoa]['.$ctngay['id'].'] value='.$ctngay['soluong'].'></td>';
			}	
		}
	endforeach;?>
<td><?php echo $form->input('ghichu',array('label'=>false,'id'=>'ghichu','type'=>'textarea','value'=>$chitieungays['Kehoachbhld']['ghichu']))?></td>
</tr>
</table>
<fieldset>
<legend> Địa điểm</legend>
<table>
<tr>
<td><?php echo $form->input('cap1',array('label'=>'Tỉnh/Thành Phố','id'=>'cap1','type'=>'select','options'=>$diadiems,'empty'=>' --Chọn Tỉnh/Thành Phố--','selected'=>$ddc1['Diadiem']['id']))?></td>
<td><div id='cap2'><?php echo $form->input('cap2',array('label'=>'Huyện','class'=>'cap2','type'=>'select','options'=>$ddiemsc2,'empty'=>' --Chọn Quận Huyện--','selected'=>$ddc2['Diadiem']['id']))?></div></td>
<td><div id='cap3'><?php echo $form->input('cap3',array('label'=>'Xã','class'=>'cap3','type'=>'select','options'=>$ddiemsc3,'empty'=>' --Chọn Xã/Thị Trấn--','selected'=>$ddc3['Diadiem']['id']))?></div></td>
<td><div id='cap4'><?php echo $form->input('cap4',array('label'=>'Khu vực/Ấp','class'=>'cap4','type'=>'select','options'=>$ddiemsc4,'empty'=>' --Khu vực/Ấp--','selected'=>$ddc4['Diadiem']['id']))?></div></td>
</tr>

</table>
</fieldset>
<?php // debug($ddc1['Diadiem']['diadiem_id']);?>
<?php echo $form->end('  Lưu  ');?>
<?php
$this->Js->get('#cap1')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap2'),
							array('update' => '#cap2','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap2')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap3'),
							array('update' => '#cap3','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap1')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'emptycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

$this->Js->get('#cap1')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap3'),
							array('update' => '#cap3','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
							
$this->Js->get('#cap2')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'emptycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
							
$this->Js->get('#cap3')->event('change',
							$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laycap4'),
							array('update' => '#cap4','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
?>
